<html>
<head><meta charset="utf-8"><title>simd-variants for impls · t-libs/stdarch · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/index.html">t-libs/stdarch</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html">simd-variants for impls</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="177036492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177036492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177036492">(Oct 01 2019 at 09:07)</a>:</h4>
<p>Do we have any documentation/pattern/proc_macro already on what's the best way to write simd-specific variants?</p>



<a name="177037511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177037511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177037511">(Oct 01 2019 at 09:23)</a>:</h4>
<p>What do you mean by “variants”?</p>



<a name="177038645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177038645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177038645">(Oct 01 2019 at 09:38)</a>:</h4>
<p>you have some function you can reimplement using arch-specific simd (or even assembly directly)</p>



<a name="177038681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177038681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177038681">(Oct 01 2019 at 09:38)</a>:</h4>
<p>you would like to select at runtime which one to use</p>



<a name="177038869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177038869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177038869">(Oct 01 2019 at 09:42)</a>:</h4>
<p>The students trying to add neon support in rav1e shown me that what I consider self-explaining and basic is not</p>



<a name="177057042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177057042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177057042">(Oct 01 2019 at 13:54)</a>:</h4>
<p>There are crates in <a href="http://crates.io" target="_blank" title="http://crates.io">crates.io</a> for doing that but the std arch docs should cover the rest, otherwise there is also the RFC</p>



<a name="177070031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177070031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177070031">(Oct 01 2019 at 16:05)</a>:</h4>
<p><span class="user-mention" data-user-id="131070">@Luca Barbato</span> cfg-if 0.1.10 recently got support so it works inside methods, you can also do runtime detection of course</p>



<a name="177073105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177073105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177073105">(Oct 01 2019 at 16:37)</a>:</h4>
<p>Do you have other crates in mind?</p>



<a name="177098571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177098571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177098571">(Oct 01 2019 at 21:12)</a>:</h4>
<p>What you're using SIMD for greatly affects the sort of API you want to build.</p>
<p>I recently released 0.1 of the <code>wide</code> crate which aims to have an f32x4 type that is as close as possible to being a drop-in replacement for normal f32. It supports all traits and methods that f32 does except for eq/ord. I'm honestly not sure how I'll handle those.</p>
<p>You can just use intrinsics/asm and runtime detection, but runtime detecting has a small cost so usually you need to run your check once, do a fair amount of SIMD to make up for the cost of the check (not just 1 add or something), and then have fallbacks too and all that. I wouldn't do that myself. I've always stuck to compile time checks only</p>



<a name="177098628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177098628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177098628">(Oct 01 2019 at 21:12)</a>:</h4>
<p>Also, if you use arrays of 4 and align it to 16 then _most_ of the work will be done for you by llvm</p>



<a name="177098665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177098665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177098665">(Oct 01 2019 at 21:13)</a>:</h4>
<p>of course that's with optimizations on, you need to write it by hand if you want debug performance too</p>



<a name="177098795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177098795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177098795">(Oct 01 2019 at 21:14)</a>:</h4>
<p>unfortunately it's kinda specific to the SIMD set you want. A neon oriented library will probably end up different from an sse based library</p>



<a name="177137057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177137057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177137057">(Oct 02 2019 at 10:15)</a>:</h4>
<p>In my case I need to boost the dispatch part, not the writing part (we share asm code with another project).</p>



<a name="177304630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177304630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177304630">(Oct 04 2019 at 01:58)</a>:</h4>
<p>just gotta use std. Unfortunately, detecting it at runtime demands that you interface with the OS to handle all the edge cases properly. you can check the implementation of the <code>is_x86_feature_detected!</code> macro if you want to get into the details there.</p>



<a name="177461770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177461770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177461770">(Oct 06 2019 at 13:38)</a>:</h4>
<p>that part is done, I'm thinking on make the whole experience more streamlined</p>



<a name="177461826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177461826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177461826">(Oct 06 2019 at 13:40)</a>:</h4>
<p>e.g. auto-populate/auto-generate impl blocks and provide facilities to instantiate the right variant to call around the code</p>



<a name="177461841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177461841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177461841">(Oct 06 2019 at 13:41)</a>:</h4>
<p>since currently the experience isn't better than the C-way of making a struct of fn, populate it and then call from the struct</p>



<a name="177781569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177781569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177781569">(Oct 10 2019 at 05:54)</a>:</h4>
<p><span class="user-mention" data-user-id="131070">@Luca Barbato</span> check out the “multiversion” crate</p>



<a name="177784156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177784156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177784156">(Oct 10 2019 at 06:56)</a>:</h4>
<p>That's quite similar to what I had in mind, I wanted to use attributes and impl blocks, this is probably even better :)</p>



<a name="177784478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/simd-variants%20for%20impls/near/177784478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/simd-variants.20for.20impls.html#177784478">(Oct 10 2019 at 07:02)</a>:</h4>
<p>(even if it is a bit overkill in the way it works... )</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>